﻿using System;
using System.Collections.Generic;
using O2DESNet;
using ShkSimulation.core.dao.statistic;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.customer;

namespace ShkSimulation.carsharing.impl.elements {
    public class Dispatcher : CarsharingTraveler, DataReporter {
        
        public int DispatchCount { get; private set; }

        public string uniquekey;

        public string Uniquekey => uniquekey;
        
        public string Name => uniquekey;

        public Dispatcher(string name) {
            this.IsDispatcher = true;
            this.uniquekey = name;
        }

        public event Action<DataReporter> ReportToCollection = _ => { };
        
        private Dictionary<string, double> reportRelatedDoubleData =
            new Dictionary<string, double>();

        
        public DataReportInfo GetReportInfo() {
            reportRelatedDoubleData["调度次数"] = DispatchCount;
            return DataReportInfo.Create(Uniquekey, DateTime.MinValue, null, reportRelatedDoubleData);
        }

        public virtual Dictionary<string, ReadOnlyHourCounter> GetReportRelatedProperty() {
            return new Dictionary<string, ReadOnlyHourCounter>();
        }

        internal void SetRoute(List<Agency> agencies) {
            this.SetAgenciesAndCloneAgencies(agencies);
        }

        internal void EndDispatch(DateTime clockTime) {
            this.TotalTravelTime += clockTime - this.TimeLeaveStation;
            this.DispatchCount++;
        }
        
        internal void StartDispatch(DateTime clockTime) {
            this.TimeLeaveStation = clockTime;
            this.EnterNextAgency();
        }

        public override void ExistNetwok() {
            
        }

    }
}
